package com.dxc.intern.controller;


import com.dxc.intern.entity.Roster;
import com.dxc.intern.service.RosterService;
import com.dxc.untils.result.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 花名册(已入职) 前端控制器
 * </p>
 *
 * @author zhangchengming
 * @since 2022-02-21
 */
@RestController
@RequestMapping("/roster")
public class RosterController {

    @Autowired
    private RosterService rosterService;


    @PostMapping("/insert")
    public ResultUtil<?> insert(@RequestBody Roster roster){
        rosterService.save(roster);
        return ResultUtil.success("新增成功");
    }
    @PostMapping("/updata")
    public ResultUtil<?> updata(@RequestBody Roster roster){
        rosterService.updateById(roster);
        return ResultUtil.success("更新成功");
    }
    @DeleteMapping("/deletebyid/{id}")
    public ResultUtil<?> deleteById(@PathVariable Long id){
        rosterService.removeById(id);
        return ResultUtil.success("删除成功");
    }
    @GetMapping("/page")
    public ResultUtil<?> pages(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                               @RequestParam(name = "name",defaultValue = "")String name,
                               @RequestParam(name = "phone",defaultValue = "")String phone,
                               @RequestParam(name = "postion",defaultValue = "")String postion,
                               @RequestParam(name = "education",defaultValue = "")String education,
                               @RequestParam(name = "school",defaultValue = "")String school,
                               @RequestParam(name = "addr",defaultValue = "")String addr){

        return ResultUtil.success(rosterService.selectPage(pageNo,pageSize,name,phone,postion,education,school,addr));
    }
}
